package com.amarsoft.tpf.concurrent.executeunit;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.amarsoft.tpf.TPFException;
import com.amarsoft.tpf.connection.Connection;
import com.amarsoft.tpf.executor.Executor;

public class ExecuteTransaction extends RunExecuteUnit {
	private Connection connection;
	private Executor executor;
	
	@Override
	protected void threadRun() {
		try {
			if(connection != null && executor == null){
				connection.open();
				connection.execute(getTransaction());
				connection.close();
			}else if(connection == null && executor != null){
				executor.doChain(getTransaction());
			}
		} catch (IOException e) {
			e.printStackTrace();
		} catch (TPFException e) {
			e.printStackTrace();
		} catch (TimeoutException e) {
			e.printStackTrace();
		}
	}

	public Connection getConnection() {
		return connection;
	}

	public void setConnection(Connection connection) {
		this.connection = connection;
	}

	public Executor getExecutor() {
		return executor;
	}

	public void setExecutor(Executor executor) {
		this.executor = executor;
	}
}
